﻿using System;
using NUnit.Framework;
using ProjetoComperio.Framework.Extensions;

namespace ProjetoComperio.Test.ComperioFramework.Extensions
{

    [TestFixture]
    public class EntityObjectExtensionsTest
    {
        [Test]
        public void TestCopyValuesFrom()
        {

            MyClass obj1 = new MyClass();
            obj1.propDateTime = DateTime.Now.Date;
            obj1.propDecimal = 101;
            obj1.propInteger = 2;
            obj1.propString = "Value";

            MyClass obj2 = new MyClass();
            obj2.CopyValuesFrom(obj1);


            Assert.IsTrue(obj2.propDateTime == obj1.propDateTime);
            Assert.IsTrue(obj2.propDecimal == obj1.propDecimal);
            Assert.IsTrue(obj2.propInteger == obj1.propInteger);
            Assert.IsTrue(obj2.propString == obj1.propString);


        }
        private MyClass2 GenerateMyClass2()
        {
            MyClass2 obj1 = new MyClass2();
            obj1.MyClass2Id = 1;
            obj1.propDateTime = DateTime.Now;
            obj1.propDecimal = 10;
            obj1.propInteger = 1;
            obj1.propString = "String";
            return obj1;
        }
        [Test]
        public void TestCopyValuesFrom_WithoutCopyId()
        {
            var obj1 = GenerateMyClass2();
            var obj2 = new MyClass2();
            obj2.CopyValuesFrom(obj1);
            Assert.AreEqual(0, obj2.MyClass2Id);
        }


    }

    public class MyClass : Object
    {
        public String propString { get; set; }
        public Int32 propInteger { get; set; }
        public DateTime propDateTime { get; set; }
        public Decimal propDecimal { get; set; }
    }

    internal class MyClass2 : MyClass
    {
        [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
        public Int32 MyClass2Id { get; set; }

    }
}
